const express = require('express')
const cors = require('cors')
const morgan = require('morgan')

const router = require('./router')

const app = express()

// 中间件
app.use(express.json()) // 解析json请求
app.use(express.urlencoded()) // 解析urlencoded请求
app.use(cors()) // 支持跨域请求
app.use(morgan('dev')) // 日志记录的中间件
app.use(express.static('public')) // 处理静态资源

app.use('/api/v1', router)

// app.use(errorHandler())
const PORT = process.env.PORT || 8888
app.listen(PORT, () => {
  console.log(`Server is running at http://localhost:${PORT}`)
})
